package com.tuo51;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
//@Profile({"dev"})
public class Swagger2 {

    @Bean
    public Docket createBizGameApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(bizGameApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.bizgame"))
                .paths(PathSelectors.any())
                .build()
                .groupName("运营游戏");
    }

    private ApiInfo bizGameApiInfo() {
        return new ApiInfoBuilder()
                .title("运营游戏 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createObRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(obApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.observation"))
                .paths(PathSelectors.any())
                .build()
                .groupName("观测点小程序");
    }

    private ApiInfo obApiInfo() {
        return new ApiInfoBuilder()
                .title("观测点小程序 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createMpRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(mpApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.childcare"))
                .paths(PathSelectors.any())
                .build()
                .groupName("月评月优服务号");
    }

    private ApiInfo mpApiInfo() {
        return new ApiInfoBuilder()
                .title("月评月优 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createOpRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(opApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.manager"))
                .paths(PathSelectors.any())
                .build()
                .groupName("托无忧运营支撑系统");
    }

    private ApiInfo opApiInfo() {
        return new ApiInfoBuilder()
                .title("托无忧运营支撑系统 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createPartnerRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(partnerApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.partner"))
                .paths(PathSelectors.any())
                .build()
                .groupName("托无忧伙伴业务支撑");
    }

    private ApiInfo partnerApiInfo() {
        return new ApiInfoBuilder()
                .title("托无忧伙伴业务支撑 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createMaRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(maApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.evaluate"))
                .paths(PathSelectors.any())
                .build()
                .groupName("无忧测评小程序");
    }

    private ApiInfo maApiInfo() {
        return new ApiInfoBuilder()
                .title("无忧测评小程序 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }

    @Bean
    public Docket createWxRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(wxApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.wx"))
                .paths(PathSelectors.any())
                .build()
                .groupName("托无忧微信接入");
    }

    @Bean
    public Docket createBdRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(wxApiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.tuo51.bytedance"))
                .paths(PathSelectors.any())
                .build()
                .groupName("托无忧字节跳动接入");
    }


    private ApiInfo wxApiInfo() {
        return new ApiInfoBuilder()
                .title("托无忧微信接入 API 文档")
                .description("")
                .termsOfServiceUrl("http://tuo51.com/")
                .contact(new Contact("Ron","http://sigarron.dev", "luoying@tuo51.com"))
                .version("1.0")
                .build();
    }
}
